package com.func.domain.activity.repository;

import com.func.domain.activity.model.aggregate.CreatePartakeOrderAggregate;
import com.func.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import com.func.domain.activity.model.entity.*;
import com.func.domain.activity.model.valobj.ActivitySkuStockKeyVO;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * IActivityRepository
 * </p>
 *
 * @author Simon
 * @version 2025.03.11.1.0.0
 * @description IActivityRepository
 * @since 2025-03-11
 */

public interface IActivityRepository {
        /**
         * 通过SKU, 查询到sku实体
         * @param sku sku编号
         * @return 活动SKU实体
         */
        ActivitySkuEntity queryActivitySku(Long sku);

        /**
         * 根据活动ID, 查询到活动实体对象
         * @param activityId 活动ID
         * @return 活动实体对象
         */
        ActivityEntity queryRaffleActivityByActivityId(Long activityId);

        /**
         *
         * @param activityCountId 活动次数配置ID
         * @return 活动次数配置实体类
         */
        ActivityCountEntity queryActivityCountByActivityCountId(Long activityCountId);

        /**
         * 活动sku库存预热进redis中
         * @param cacheKey key
         * @param stockCount value
         */
        void cacheActivitySkuStock(String cacheKey, Integer stockCount);

        /**
         * 扣减活动sku库存
         * @param sku skuID
         * @param cacheKey redis key
         * @param endDateTime 活动截止时间
         * @return 活动sku库存是否扣减成功
         */
        boolean subtractionActivitySkuStock(Long sku, String cacheKey, Date endDateTime);

        /**
         * 将库存扣减的动作写入redis中的延迟队列中
         * @param activitySkuStockKeyVO 活动库存扣减的key值对象
         */
        void activitySkuStockConsumeSendQueue(ActivitySkuStockKeyVO activitySkuStockKeyVO);

        ActivitySkuStockKeyVO takeQueueValue();

        void clearQueueValue();

        void updateActivitySkuStock(Long sku);

        void clearActivitySkuStock(Long sku);

        /**
         * 查询有没有没用过的用户订单
         * @param partakeRaffleActivityEntity 用户参与活动的必要物料
         * @return 用户没用过的订单
         */
        UserRaffleOrderEntity queryNoUsedRaffleOrder(PartakeRaffleActivityEntity partakeRaffleActivityEntity);

        /**
         * 保存参与活动订单聚合对象入库
         * @param createPartakeOrderAggregate 活动订单聚合对象
         */
        void saveCreatePartakeOrderAggregate(CreatePartakeOrderAggregate createPartakeOrderAggregate);

        /**
         * 查询用户账户总次数账户
         * @param userId 用户ID
         * @param activityId 活动ID
         * @return 用户总次数账户实体
         */
        ActivityAccountEntity queryActivityAccountByUserId(String userId, Long activityId);

        /**
         * 查询用户账户月次数账户
         * @param userId 用户ID
         * @param activityId 活动ID
         * @param month 哪月的月剩余次数
         * @return 用户月次数账户实体
         */
        ActivityAccountMonthEntity queryActivityAccountMonthByUserId(String userId, Long activityId, String month);

        /**
         * 查询用户账户日次数账户
         * @param userId 用户ID
         * @param activityId 活动ID
         * @param day 哪天的日剩余次数
         * @return 用户日次数账户实体
         */
        ActivityAccountDayEntity queryActivityAccountDayByUserId(String userId, Long activityId, String day);

    List<ActivitySkuEntity> queryActivitySkuListByActivityId(Long activityId);

    Integer queryRaffleActivityAccountDayPartakeCount(Long activityId, String userId);

    ActivityAccountEntity queryActivityAccountEntity(String userId, Long activityId);

    void updateCreditOrder(DeliveryOrderEntity deliveryOrderEntity);

    void doSaveCreditPayOrder(CreateQuotaOrderAggregate createQuotaOrderAggregate);

    void doSaveNoPayOrder(CreateQuotaOrderAggregate createQuotaOrderAggregate);

        UnpaidActivityOrderEntity queryUnpaidActivityOrder(SkuRechargeEntity skuRechargeEntity);

    List<SkuProductEntity> querySkuProductEntityListByActivityId(Long activityId);

    BigDecimal queryUserCreditAccountAmount(String userId);
}
